package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.BuildingStyle;
import com.jiayang.hhotel.listener.OnItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/10 0010.
 */

public class SetPermissionsAdapter extends SwipeMenuAdapter<BuildingStyleAdapter.DefaultViewHolder>{

    private Context context;
    private List<BuildingStyle> buildingStyles;
    private int i = 0;
    private OnItemClickListener mOnItemClickListener;

    public SetPermissionsAdapter(List<BuildingStyle> titles, Context context) {
        this.buildingStyles = titles;
        this.context=context;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemCount() {
        return buildingStyles == null ? 0 : buildingStyles.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.listitemsetpermission, parent, false);
    }

    @Override
    public BuildingStyleAdapter.DefaultViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        BuildingStyleAdapter.DefaultViewHolder viewHolder = new BuildingStyleAdapter.DefaultViewHolder(realContentView);
        viewHolder.mOnItemClickListener = mOnItemClickListener;
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BuildingStyleAdapter.DefaultViewHolder holder, int position) {
        
    }


    static class DefaultViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvTitle;
        OnItemClickListener mOnItemClickListener;

        public DefaultViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        }

        public void setData(String title) {
            this.tvTitle.setText(title);
        }

        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(getAdapterPosition());
            }
        }
    }
}
